using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using MvcExtExample.Models;

namespace MvcExtExample.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult OilFieldMonthCurve()
        {
            if (Session["LogedUser"] == null)
                return View("Index");
            return View();
        }

        public ActionResult CYJMonthCurve()
        {
            if (Session["LogedUser"] == null)
                return View("Index");
            return View();
        }

        public ActionResult ZSJMonthCurve()
        {
            if (Session["LogedUser"] == null)
                return View("Index");
            return View();
        }

        public ActionResult CQJMonthCurve()
        {
            if (Session["LogedUser"] == null)
                return View("Index");
            return View();
        }

        //“我的登录历史记录”页面
        public ActionResult loginHistory()
        {
            if (Session["LogedUser"] == null)
                return View("Index");
            return View();
        }

        //获取登录历史记录的总数
        public int GetloginHistoryCount()
        {
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            string strSqlGetloginHistoryCount = "SELECT COUNT(*) FROM [dbo].[Tb_LogOperation] WHERE [OperationType]='登录' ";
            int loginHistoryCount = 0;
            loginHistoryCount = cs.ReturnSQL(strSqlGetloginHistoryCount);
            return loginHistoryCount;
        }

        //“修改密码”页面
        public ActionResult modifyPwd()
        {

            if (Session["LogedUser"] == null)
                return View("Index");
            return View();
        }

        //采油井单井月曲线
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CYJMonthCurveQuery(ControllerContext controllerContext)
        {
            //从请求中获取提交的参数数据 
            //string WorkZoneSelect = HttpContext.Request.Params["WorkZoneSelect"] ?? "";
            //string SCDDSelect = HttpContext.Request.Params["SCDDSelect"] ?? "";
            //string JXSelect = HttpContext.Request.Params["JXSelect"] ?? "";
            string JHSelect = HttpContext.Request.Params["JHSelect"] ?? "CYJJ_1_1_1_1";
            string productdate = HttpContext.Request.Params["productdate_box"] ?? "2014-09";
            List<CYJMonthModel> litestModel = new List<CYJMonthModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            if (!String.IsNullOrEmpty(JHSelect) && !String.IsNullOrEmpty(productdate))
            {
                #region 获取这个月的每天的日期
                string month = productdate.Substring(productdate.Length - 1, 1);
                string year = productdate.Substring(0, 4);
                List<string> Date = new List<string>();
                string strSqlGetDateList = "SELECT DISTINCT [Date] FROM [dbo].[Tb_Oil_Well] WHERE MONTH([Date])=" + month + " AND YEAR([Date])=" + year;
                DataSet DateDateSet = cs.GetDataSet(strSqlGetDateList);
                if (DateDateSet != null)
                {
                    DataTable DTable = DateDateSet.Tables[0];
                    for (int i = 0; i < DTable.Rows.Count; i++)
                    {
                        DataRowView rowview = DateDateSet.Tables[0].DefaultView[i];
                        Date.Add(rowview["Date"].ToString());
                    }
                }
                #endregion

                #region 获取这一个月内每天的油井相关指标
                List<decimal> CYJDailyOil = new List<decimal>(), CYJDailyWater = new List<decimal>(), CYJDailyGas = new List<decimal>();
                foreach (string item in Date)
                {
                    //获取这一个月内每天的日产油总量
                    string strSqlGetDailyOil = "SELECT [DailyOil] FROM [dbo].[Tb_Oil_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal DailyOil = cs.ReturnDecimalSQL(strSqlGetDailyOil);
                    CYJDailyOil.Add(DailyOil);
                    //获取这一个月内每天的日产水总量
                    string strSqlGetDailyFluid = "SELECT [DailyFluid] FROM [dbo].[Tb_Oil_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal DailyFluid = cs.ReturnDecimalSQL(strSqlGetDailyFluid);
                    CYJDailyWater.Add(DailyFluid);
                    //获取这一个月内每天的日产气总量
                    string strSqlGetDailyGas = "SELECT [DailyGas] FROM [dbo].[Tb_Oil_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal DailyGas = cs.ReturnDecimalSQL(strSqlGetDailyGas);
                    CYJDailyGas.Add(DailyGas);
                }
                #endregion

                #region 填充litestModel
                for (int i = 0; i < Date.Count; i++)
                {
                    litestModel.Add(new CYJMonthModel()
                    {
                        name = (i + 1).ToString(),
                        Oil_Production = CYJDailyOil[i],
                        Water_Injection = CYJDailyWater[i],
                        Gas_Production = CYJDailyGas[i]
                    });
                }
                #endregion

                return Json(litestModel, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return null;
            }
        }

        //注水井单井月曲线
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult ZSJMonthCurveQuery(ControllerContext controllerContext)
        {
            //从请求中获取提交的参数数据
            string JHSelect = HttpContext.Request.Params["JHSelect"] ?? "ZSJ_1_1_1_1";
            string productdate = HttpContext.Request.Params["productdate_box"] ?? "2014-09";
            List<ZSJMonthModel> litestModel = new List<ZSJMonthModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            if (!String.IsNullOrEmpty(JHSelect) && !String.IsNullOrEmpty(productdate))
            {
                #region 获取这个月的每天的日期
                string month = productdate.Substring(productdate.Length - 1, 1);
                string year = productdate.Substring(0, 4);
                List<string> Date = new List<string>();
                string strSqlGetDateList = "SELECT DISTINCT [Date] FROM [dbo].[Tb_Oil_Well] WHERE MONTH([Date])=" + month + " AND YEAR([Date])=" + year;
                DataSet DateDateSet = cs.GetDataSet(strSqlGetDateList);
                if (DateDateSet != null)
                {
                    DataTable DTable = DateDateSet.Tables[0];
                    for (int i = 0; i < DTable.Rows.Count; i++)
                    {
                        DataRowView rowview = DateDateSet.Tables[0].DefaultView[i];
                        Date.Add(rowview["Date"].ToString());
                    }
                }
                #endregion

                #region 获取这一个月内每天的注水井相关指标
                List<decimal> Li_Daily_Water_Time = new List<decimal>(), Li_Daily_Schedule = new List<decimal>(), Li_Daily_Actual = new List<decimal>();
                foreach (string item in Date)
                {
                    //获取这一个月内每天的日注水时间
                    string strSqlGetDaily_Water_Time = "SELECT [Daily_Water_Time] FROM [dbo].[Tb_Water_Injection_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal Daily_Water_Time = cs.ReturnDecimalSQL(strSqlGetDaily_Water_Time);
                    Li_Daily_Water_Time.Add(Daily_Water_Time);
                    //获取这一个月内每天的日计划注水量
                    string strSqlGetDaily_Schedule = "SELECT [Daily_Schedule] FROM [dbo].[Tb_Water_Injection_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal Daily_Schedule = cs.ReturnDecimalSQL(strSqlGetDaily_Schedule);
                    Li_Daily_Schedule.Add(Daily_Schedule);
                    //获取这一个月内每天的日实际注水量
                    string strSqlGetDaily_Actual = "SELECT [Daily_Actual] FROM [dbo].[Tb_Water_Injection_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal Daily_Actual = cs.ReturnDecimalSQL(strSqlGetDaily_Actual);
                    Li_Daily_Actual.Add(Daily_Actual);
                }
                #endregion

                #region 填充litestModel
                for (int i = 0; i < Date.Count; i++)
                {
                    litestModel.Add(new ZSJMonthModel()
                    {
                        name = (i + 1).ToString(),
                        Daily_Water_Time = Li_Daily_Water_Time[i],
                        Daily_Schedule = Li_Daily_Schedule[i],
                        Daily_Actual = Li_Daily_Actual[i]
                    });
                }
                #endregion

                return Json(litestModel, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return null;
            }
        }

        //采气井单井月曲线
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CQJMonthCurveQuery(ControllerContext controllerContext)
        {
            //从请求中获取提交的参数数据
            string JHSelect = HttpContext.Request.Params["JHSelect"] ?? "CQJ_1_1_1_1";
            string productdate = HttpContext.Request.Params["productdate_box"] ?? "2014-09";
            List<CQJMonthModel> litestModel = new List<CQJMonthModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            if (!String.IsNullOrEmpty(JHSelect) && !String.IsNullOrEmpty(productdate))
            {
                #region 获取这个月的每天的日期
                string month = productdate.Substring(productdate.Length - 1, 1);
                string year = productdate.Substring(0, 4);
                List<string> Date = new List<string>();
                string strSqlGetDateList = "SELECT DISTINCT [Date] FROM [dbo].[Tb_Oil_Well] WHERE MONTH([Date])=" + month + " AND YEAR([Date])=" + year;
                DataSet DateDateSet = cs.GetDataSet(strSqlGetDateList);
                if (DateDateSet != null)
                {
                    DataTable DTable = DateDateSet.Tables[0];
                    for (int i = 0; i < DTable.Rows.Count; i++)
                    {
                        DataRowView rowview = DateDateSet.Tables[0].DefaultView[i];
                        Date.Add(rowview["Date"].ToString());
                    }
                }
                #endregion

                #region 获取这一个月内每天的采气井相关指标
                List<decimal> Li_DailyGas = new List<decimal>(), Li_DailyOil = new List<decimal>(), Li_DailyWater = new List<decimal>();
                foreach (string item in Date)
                {
                    //获取这一个月内每天的日注水时间
                    string strSqlGetDailyGas = "SELECT [DailyGas] FROM [dbo].[Tb_Gas_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal DailyGas = cs.ReturnDecimalSQL(strSqlGetDailyGas);
                    Li_DailyGas.Add(DailyGas);
                    //获取这一个月内每天的日计划注水量
                    string strSqlGetDailyOil = "SELECT [DailyOil] FROM [dbo].[Tb_Gas_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal DailyOil = cs.ReturnDecimalSQL(strSqlGetDailyOil);
                    Li_DailyOil.Add(DailyOil);
                    //获取这一个月内每天的日实际注水量
                    string strSqlGetDailyWater = "SELECT [DailyWater] FROM [dbo].[Tb_Gas_Well] WHERE [Date] = '" + item + "' AND [Well_ID]='" + JHSelect + "'";
                    decimal DailyWater = cs.ReturnDecimalSQL(strSqlGetDailyWater);
                    Li_DailyWater.Add(DailyWater);
                }
                #endregion

                #region 填充litestModel
                for (int i = 0; i < Date.Count; i++)
                {
                    litestModel.Add(new CQJMonthModel()
                    {
                        name = (i + 1).ToString(),
                        DailyGas = Li_DailyGas[i],
                        DailyOil = Li_DailyOil[i],
                        DailyWater = Li_DailyWater[i]
                    });
                }
                #endregion

                return Json(litestModel, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return null;
            }
        }

        //油田月曲线
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult OilFieldMonthCurveQuery(ControllerContext controllerContext)
        {
            //从请求中获取提交的参数数据 
            string WorkZoneSelect = HttpContext.Request.Params["WorkZoneSelect"] ?? "1";
            string productdate = HttpContext.Request.Params["productdate_box"] ?? "2014-09";
            List<CYJMonthModel> litestModel = new List<CYJMonthModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            if (!String.IsNullOrEmpty(WorkZoneSelect) && !String.IsNullOrEmpty(productdate))
            {
                switch (WorkZoneSelect)
                {
                    case "大港油田":
                        WorkZoneSelect = "1";//第一作业区
                        break;
                    case "火烧山油田":
                        WorkZoneSelect = "2";//第二作业区
                        break;
                    case "北三台油田":
                        WorkZoneSelect = "3";//第三作业区
                        break;
                    case "沙南油田":
                        WorkZoneSelect = "4";//第四作业区
                        break;
                    default:
                        break;
                }

                #region 获取这个月的每天的日期
                string month = productdate.Substring(productdate.Length - 1, 1);
                string year = productdate.Substring(0, 4);
                List<string> Date = new List<string>();
                string strSqlGetDateList = "SELECT DISTINCT [Date] FROM [dbo].[Tb_Oil_Well] WHERE MONTH([Date])=" + month + " AND YEAR([Date])=" + year;
                DataSet DateDateSet = cs.GetDataSet(strSqlGetDateList);
                if (DateDateSet != null)
                {
                    DataTable DTable = DateDateSet.Tables[0];
                    for (int i = 0; i < DTable.Rows.Count; i++)
                    {
                        DataRowView rowview = DateDateSet.Tables[0].DefaultView[i];
                        Date.Add(rowview["Date"].ToString());
                    }
                }
                #endregion

                #region 获取这个作业区这一个月内每天的油井相关指标
                List<decimal> CYJDailyOil = new List<decimal>(), CYJDailyWater = new List<decimal>(), CYJDailyGas = new List<decimal>();
                foreach (string item in Date)
                {
                    //获取这一个月内每天的日产油总量
                    string strSqlGetDailyOil = "SELECT SUM([DailyOil]) FROM [dbo].[Tb_Oil_Well] WHERE [Date] = '" + item + "' AND SUBSTRING([Well_ID], CHARINDEX('_', [Well_ID]) + 1, 1) = '" + WorkZoneSelect + "'";
                    decimal DailyOil = cs.ReturnDecimalSQL(strSqlGetDailyOil);
                    CYJDailyOil.Add(DailyOil);
                    //获取这一个月内每天的日产水总量
                    string strSqlGetDailyFluid = "SELECT SUM([DailyFluid]) FROM [dbo].[Tb_Oil_Well] WHERE [Date] = '" + item + "' AND SUBSTRING([Well_ID], CHARINDEX('_', [Well_ID]) + 1, 1) = '" + WorkZoneSelect + "'";
                    decimal DailyFluid = cs.ReturnDecimalSQL(strSqlGetDailyFluid);
                    CYJDailyWater.Add(DailyFluid);
                    //获取这一个月内每天的日产气总量
                    string strSqlGetDailyGas = "SELECT SUM([DailyGas]) FROM [dbo].[Tb_Oil_Well] WHERE [Date] = '" + item + "' AND SUBSTRING([Well_ID], CHARINDEX('_', [Well_ID]) + 1, 1) = '" + WorkZoneSelect + "'";
                    decimal DailyGas = cs.ReturnDecimalSQL(strSqlGetDailyGas);
                    CYJDailyGas.Add(DailyGas);
                }
                #endregion

                #region 填充litestModel
                for (int i = 0; i < Date.Count; i++)
                {
                    litestModel.Add(new CYJMonthModel()
                    {
                        name = (i + 1).ToString(),
                        Oil_Production = CYJDailyOil[i],
                        Water_Injection = CYJDailyWater[i],
                        Gas_Production = CYJDailyGas[i]
                    });
                }
                #endregion

                return Json(litestModel, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return null;
            }
        }

        //获取工作区列表
        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult WorkZoneSelect()
        {
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID]='ALL'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["name"].ToString(),
                        value = rowview["value"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //根据当前所选工作区获取作业区下的采油大队列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult SCDDSelect()
        {
            string workZoneSelectValue = "第一作业区";
            if (!string.IsNullOrEmpty(Request.QueryString["workZoneSelectValue"]))
            {
                workZoneSelectValue = Request.QueryString["workZoneSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + workZoneSelectValue + "') AND SUBSTRING([Dep_ID], 0, 3) = 'CY'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Dep_Name"].ToString(),
                        value = rowview["Dep_Name"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //根据当前所选工作区获取作业区下的注水大队列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult ZSDDSelect()
        {
            string workZoneSelectValue = "第一作业区";
            if (!string.IsNullOrEmpty(Request.QueryString["workZoneSelectValue"]))
            {
                workZoneSelectValue = Request.QueryString["workZoneSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + workZoneSelectValue + "') AND SUBSTRING([Dep_ID], 0, 3) = 'ZS'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Dep_Name"].ToString(),
                        value = rowview["Dep_Name"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //根据当前所选工作区获取作业区下的采气大队列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CQDDSelect()
        {
            string workZoneSelectValue = "第一作业区";
            if (!string.IsNullOrEmpty(Request.QueryString["workZoneSelectValue"]))
            {
                workZoneSelectValue = Request.QueryString["workZoneSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + workZoneSelectValue + "') AND SUBSTRING([Dep_ID], 0, 3) = 'CQ'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Dep_Name"].ToString(),
                        value = rowview["Dep_Name"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //注水井#根据当前所选工作区获取作业区下的生产大队列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult ZSJ_SCDDSelect()
        {
            string workZoneSelectValue = "第一作业区";
            if (!string.IsNullOrEmpty(Request.QueryString["workZoneSelectValue"]))
            {
                workZoneSelectValue = Request.QueryString["workZoneSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + workZoneSelectValue + "') AND SUBSTRING([Dep_ID], 0, 3) = 'ZS'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Dep_Name"].ToString(),
                        value = rowview["Dep_Name"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //采气井#根据当前所选工作区获取作业区下的采气大队列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CQJ_CQDDSelect()
        {
            string workZoneSelectValue = "第一作业区";
            if (!string.IsNullOrEmpty(Request.QueryString["workZoneSelectValue"]))
            {
                workZoneSelectValue = Request.QueryString["workZoneSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + workZoneSelectValue + "') AND SUBSTRING([Dep_ID], 0, 3) = 'CQ'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Dep_Name"].ToString(),
                        value = rowview["Dep_Name"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //注水井#根据当前所选生产大队获取作业区下的生产小队列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult ZSJ_SCXDSelect()
        {
            string SCDDSelectValue = "第一注水大队";
            if (!string.IsNullOrEmpty(Request.QueryString["SCDDSelectValue"]))
            {
                SCDDSelectValue = Request.QueryString["SCDDSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + SCDDSelectValue + "') AND SUBSTRING([Dep_ID], 0, 3) = 'ZS'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Dep_Name"].ToString(),
                        value = rowview["Dep_Name"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //采气井#根据当前所选生产大队获取作业区下的采气小队列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CQJ_SCXDSelect()
        {
            string SCDDSelectValue = "第一采气大队";
            if (!string.IsNullOrEmpty(Request.QueryString["SCDDSelectValue"]))
            {
                SCDDSelectValue = Request.QueryString["SCDDSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Dep_Name] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + SCDDSelectValue + "') AND SUBSTRING([Dep_ID], 0, 3) = 'CQ'";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Dep_Name"].ToString(),
                        value = rowview["Dep_Name"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //根据当前所选“生产大队”、“井类型”获取井列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult JHSelect()
        {
            //string workZoneSelectValue = "第一作业区";
            string strSCDD = "第一采油大队";
            string strJX = "抽油机井";
            //if (!string.IsNullOrEmpty(Request.QueryString["workZoneSelectValue"]))
            //{
            //    workZoneSelectValue = Request.QueryString["workZoneSelectValue"].ToString().Trim();
            //}
            if (!string.IsNullOrEmpty(Request.QueryString["strSCDD"]))
            {
                strSCDD = Request.QueryString["strSCDD"].ToString().Trim();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["strJX"]))
            {
                strJX = Request.QueryString["strJX"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Well_ID] FROM [dbo].[Tb_CommonWell] WHERE [Dep_ID] IN ( SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [ParentDep_ID] IN ( SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + strSCDD + "')) AND SUBSTRING([Well_ID],0,CHARINDEX('_',[Well_ID])) IN (SELECT SUBSTRING([Well_Type_ID],4,5) FROM [dbo].[Tb_Well_Type] WHERE [Well_Type_Name]='" + strJX + "')";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Well_ID"].ToString(),
                        value = rowview["Well_ID"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //根据当前所选“注水小队”获取井号列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult ZSJ_JHSelect()
        {
            string ZSXDSelectValue = "第一注水小队";
            if (!string.IsNullOrEmpty(Request.QueryString["SCDDSelectValue"]))
            {
                ZSXDSelectValue = Request.QueryString["SCDDSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Well_ID] FROM [dbo].[Tb_CommonWell] WHERE [Dep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + ZSXDSelectValue + "')";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Well_ID"].ToString(),
                        value = rowview["Well_ID"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //根据当前所选“采气小队”获取井号列表
        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult CQJ_JHSelect()
        {
            string ZSXDSelectValue = "第一采气小队";
            if (!string.IsNullOrEmpty(Request.QueryString["SCDDSelectValue"]))
            {
                ZSXDSelectValue = Request.QueryString["SCDDSelectValue"].ToString().Trim();
            }
            List<selectModel> listWorkZones = new List<selectModel>();
            framework.JSONHelper jsonHelp = new framework.JSONHelper();
            string strSqlStr = "SELECT [Well_ID] FROM [dbo].[Tb_CommonWell] WHERE [Dep_ID] IN (SELECT [Dep_ID] FROM [dbo].[Tb_Department] WHERE [Dep_Name]='" + ZSXDSelectValue + "')";
            framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            DataSet DSet = cs.GetDataSet(strSqlStr);
            if (DSet != null)
            {
                DataTable DTable = DSet.Tables[0];
                for (int i = 0; i < DTable.Rows.Count; i++)
                {
                    DataRowView rowview = DSet.Tables[0].DefaultView[i];
                    listWorkZones.Add(new selectModel()
                    {
                        name = rowview["Well_ID"].ToString(),
                        value = rowview["Well_ID"].ToString()
                    });
                }
            }
            return Json(listWorkZones, JsonRequestBehavior.AllowGet);
        }

        //修改密码
        public ActionResult updatePwd(string txtOldPwd, string txtNewPwd, string txtConfirmPwd)
        {
            if (txtNewPwd != txtConfirmPwd)
                return Content("两次密码不一致！");
            txtNewPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtNewPwd, "MD5");
            bool result = updatePwdDAL(txtOldPwd, txtNewPwd, txtConfirmPwd);
            if (result)
                return Content("更新成功！");
            else
                return Content("更新失败！");
        }

        public bool updatePwdDAL(string txtOldPwd, string txtNewPwd, string txtConfirmPwd)
        {
            bool result = false;
             framework.SqlHelperCS.SqlHelper cs = new framework.SqlHelperCS.SqlHelper();
            //初始化查询语句
            string strSql = "UPDATE [dbo].[Tb_User] SET [Password] = '" + txtNewPwd + "'";
            //对SQL Server数据库执行一个transact-SQL语句
            int rows = cs.RunSQL(strSql);
            if (rows > 0)
                result = true;
            return result;
        }

    }
}
